//
//  SixinViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/14.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "SixinViewController.h"
#import "SixinTableViewCell.h"
#import "ChatViewController.h"
@interface SixinViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * contentTableView;
    NSArray * dataArr;
}
@end

@implementation SixinViewController


-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    self.navigationItem.title = @"私信";

    contentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height, ScreenWidth, ScreenHeight - rectStatus.size.height - rectNav.size.height) style:UITableViewStylePlain];
    contentTableView.delegate = self;
    contentTableView.dataSource = self;
    contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:contentTableView];
    
    [self requestData];
}

-(void)requestData
{
    [NetRequestCenter privatelistwithpage:@"" result:^(BOOL success, NSDictionary *resultDic) {
        if (success) {
            dataArr = [[resultDic objectForKey:@"data"]objectForKey:@"Detail"];
            [contentTableView reloadData];
        }
    }];
}

#pragma mark - tableview

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArr count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [SixinTableViewCell height];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifer = @"identifer";
    SixinTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[SixinTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    [cell loadData:[dataArr objectAtIndex:indexPath.row]];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ChatViewController * chat = [[ChatViewController alloc]init];
    chat.contentid = [[dataArr objectAtIndex:indexPath.row]objectForKey:@"GroupID"];
    chat.targetPic = [[dataArr objectAtIndex:indexPath.row]objectForKey:@"TalkToUserPic"];
    NSLog(@"sixinTargetPic-%@", chat.targetPic);
    chat.targetUid = [[dataArr objectAtIndex:indexPath.row]objectForKey:@"TalkToUserUID"];
    chat.targetName = [[dataArr objectAtIndex:indexPath.row]objectForKey:@"TalkToUserName"];
    [self.navigationController pushViewController:chat animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
